package wechat.app.corp.domain

import org.apache.log4j.Logger
import wechat.app.WCCorpApplication
import wechat.app.WXCorpAppFactory

class EngineerNotificationCorpWeChat{
	static Logger logger = Logger::getLogger("EngineerNotificationCorpWeChat")
	private static String CALLBACK_SERVER_URL = "http://210.22.183.30:8090"
//	def static void sendNormalNotification(Iterable<String> users, String title, String body, String id){
//		WXCorpAppFactory::customerApp=>[
//			createNews()=>[
//				withItem(title)=>[
////					picurl = CALLBACK_SERVER_URL+"/sample.jpg"
//					url = generateNotificationDetailsUrl(id)
//					logger.info('url========>'+url)
//				]
//				withItem(body)=>[
////					picurl = CALLBACK_SERVER_URL+"/smallsample.jpg"
//					url= generateNotificationDetailsUrl(id)
//				]
//				send2Users(users)
//			]
//		]
//	}
//	def static void sendEngineerTrainingNotification(Iterable<String> users, Date date, String location, String topic, String trainingID){
//		sendNormalNotification(newArrayList('rock20110501'), '培训通知','',CALLBACK_SERVER_URL)
//	}
	def static String generateNotificationDetailsUrl(String id){
		CALLBACK_SERVER_URL+'/notificationdetail?notificationId='+id
	}
	def static void sendNormalNotification(WCCorpApplication app, Iterable<String> users, String title, String body, String id){
		users.forEach[
			println('==========>send to '+ it)
		]
		app.createNews()=>[
				withItem(title)=>[
//					picurl = CALLBACK_SERVER_URL+"/sample.jpg"
					url = generateNotificationDetailsUrl(id)
//					logger.info('url========>'+url)
				]
				withItem(body)=>[
//					picurl = CALLBACK_SERVER_URL+"/smallsample.jpg"
					url= generateNotificationDetailsUrl(id)
				]
				send2Users(users)
			]
	}
	
	def static void respondMenuEvent (String wechatid, String state) {
		WXCorpAppFactory::getDefaultCorpApp=>[
			createNews()=>[
				if (state == "100") {
					withItem('工单列表')=>[
	//					picurl = CALLBACK_SERVER_URL+"/sample.jpg"
						url= "http://210.22.183.30:8090/mylist?wechatid=" + wechatid + "&state=100"
					]
				} else if (state == "101") {
					withItem('通知列表')=>[
	//					picurl = CALLBACK_SERVER_URL+"/smallsample.jpg"
						url= "http://210.22.183.30:8090/mylist?wechatid=" + wechatid + "&state=101"
					]
				}
				send2Users(newArrayList(wechatid))
			]
		]
	}
}